﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SimhoppKjellsFavoriterVT13
{
    public class Jump
    {
        public string jumpID { get; set; }
        public float difficulty;
        public float totalPoints = 0;
        public List<Judge> Judges = new List<Judge>();

        public float calculateTotalPoints()
        {
            float minScore = 10;
            float maxScore = 0;
            float totalPointsTemp = 0;

            for(int i = 1; i < Judges.Count + 1; i++)
            {
                float points = calculatePointsForJudge(i);
                if (points < 0)
                {
                    return -1;
                }

                totalPointsTemp += points;
                if (points < minScore)
                {
                    minScore = points;
                }
                else if (points > maxScore)
                {
                    maxScore = points;
                }
            }
            totalPointsTemp = totalPointsTemp - (minScore + maxScore);

            totalPointsTemp *= difficulty;
            return totalPointsTemp;
        }

        public float calculatePointsForJudge(int judge)
        {
            float points = 0;
            if (getJudge(judge) != null)
            {
                points = getJudge(judge).Takeoff + getJudge(judge).Flight + getJudge(judge).Entry + getJudge(judge).Approach;
                if (points < 0 || points > 10)
                {
                    points = -1;
                }
                getJudge(judge).Total = points;
            }
            return points;
        }

        public Judge getJudge(int judge)
        {
            int i = 1;
            foreach (Judge j in Judges)
            {
                if (judge == i)
                {
                    return j;
                }
                i++;
            }
            return null;
        }


        public void addJudge(Judge j)
        {
            Judges.Add(j);
        }
    }
}